package com.sugon.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import com.sugon.dao.InspectionRecordingJoinDao;
import com.sugon.entity.InspectionRecordingJoinEntity;
import com.sugon.service.InspectionRecordingJoinService;
import com.sugon.utils.Constant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 巡检记录选项关联Service实现类
 *
 * @author sugon
 * @date 2020-02-12 15:12:40
 */
@Service("inspectionRecordingJoinService")
public class InspectionRecordingJoinServiceImpl implements InspectionRecordingJoinService {
    @Autowired
    private InspectionRecordingJoinDao inspectionRecordingJoinDao;

    /**
     * queryObject
     *
     * @param id 主键
     * @return
     */
    @Override
    public InspectionRecordingJoinEntity queryObject(String id) {
        return inspectionRecordingJoinDao.queryObject(id);
    }

    /**
     * queryList
     *
     * @param map 参数
     * @return
     */
    @Override
    public List<InspectionRecordingJoinEntity> queryList(Map<String, Object> map) {
        return inspectionRecordingJoinDao.queryList(map);
    }

    /**
     * queryListByDEV
     *
     * @param map
     * @return
     */
    @Override
    public List<Map<String, Object>> queryListByDEV(Map<String, Object> map) {
        return inspectionRecordingJoinDao.queryListByDEV(map);
    }

    /**
     * queryTotal
     *
     * @param map 参数
     * @return
     */
    @Override
    public int queryTotal(Map<String, Object> map) {
        return inspectionRecordingJoinDao.queryTotal(map);
    }

    /**
     * queryTotalByDEV
     *
     * @param map
     * @return
     */
    @Override
    public int queryTotalByDEV(Map<String, Object> map) {
        return inspectionRecordingJoinDao.queryTotalByDEV(map);
    }

    /**
     * save
     *
     * @param inspectionRecordingJoin 实体
     * @return
     */
    @Override
    public int save(InspectionRecordingJoinEntity inspectionRecordingJoin) {
        inspectionRecordingJoin.setId(RandomUtil.randomString(32));
        inspectionRecordingJoin.setDelFlag(Constant.IS_NOT_DEL_INT);
        return inspectionRecordingJoinDao.save(inspectionRecordingJoin);
    }

    /**
     * update
     *
     * @param inspectionRecordingJoin 实体
     * @return
     */
    @Override
    public int update(InspectionRecordingJoinEntity inspectionRecordingJoin) {
        return inspectionRecordingJoinDao.update(inspectionRecordingJoin);
    }

    /**
     * delete
     *
     * @param id
     * @return
     */
    @Override
    public int delete(String id) {
        return inspectionRecordingJoinDao.delete(id);
    }

    /**
     * deleteBatch
     *
     * @param ids
     * @return
     */
    @Override
    public int deleteBatch(String[] ids) {
        return inspectionRecordingJoinDao.deleteBatch(ids);
    }

    /**
     * checkIsInspected
     *
     * @param inspectItemId 巡检项ID
     * @param devCode       设备编码
     * @return
     */
    @Override
    public boolean checkIsInspected(String inspectItemId, String devId) {
        Map<String, Object> param = new HashMap<>(3);
        param.put("opID", inspectItemId);
        param.put("devId", devId);
        param.put("nowDate", DateUtil.today());
        return inspectionRecordingJoinDao.queryTotal(param) > 0;
    }

}
